<?php
/**
 * Distribution.php
 * Niushop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2015-2025 山西牛酷信息科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: http://www.niushop.com.cn
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
 * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
 * =========================================================
 * @author : niuteam
 * @date : 2015.1.17
 * @version : v1.0.0.0
 */

namespace addons\Nsfx\api\controller;

use addons\Nsfx\data\service\NfxGoods;

use app\api\controller\BaseApi;



/**
 * 商品
 */
class Goods extends BaseApi
{
    /**
     * 获取服务中心分类
     */
	public function getRegionAgentCategory()
    {
        $title = '获取服务中心分类';

        $nfx_goods_service = new NfxGoods();
        $res = $nfx_goods_service->getRegionAgentCategory($this->uid);

        return $this->outMessage($title, $res);
    }

    /**
     * 获取服务中心分类下的产品
     */
    public function getRegionAgentCategoryGoods()
    {
        $title = '获取服务中心分类下的产品';

        $category_id = $this->params['category_id'];
        $page_index = $this->params['page_index'];
        $page_size = isset($this->params['page_size']) ? $this->params['page_size'] : 5;

        $nfx_goods_service = new NfxGoods();
        $res = $nfx_goods_service->getRegionAgentCategoryGoods([
            'uid' => $this->uid,
            'category_id' => $category_id,
        ], $page_index, $page_size);

        return $this->outMessage($title, $res);
    }

    /**
     * 获取推广商品，用于我的成就
     */
    public function getPromoterGoods()
    {
        $title = '获取推广商品，用于我的成就';

        $level = $this->params['level'];
        $category_id = $this->params['category_id'];
        $page_index = $this->params['page_index'];
        $page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGESIZE;

        $nfx_goods_service = new NfxGoods();
        $res = $nfx_goods_service->getPromoterGoods([
            'uid' => $this->uid,
            'level' => $level,
            'category_id' => $category_id,
        ], $page_index, $page_size);

        return $this->outMessage($title, $res);
    }

    /**
     * 获取推广商品下的推广员，用于xx产品邀请红旗手明细
     */
    public function getPromoterGoodsLowerPromoter()
    {
        $title = '获取推广商品下的推广员，用于xx产品邀请红旗手明细';

        $goods_id = $this->params['goods_id'];
        $page_index = $this->params['page_index'];
        $page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGESIZE;

        $nfx_goods_service = new NfxGoods();
        $res = $nfx_goods_service->getPromoterGoodsLowerPromoter([
            'uid' => $this->uid,
            'goods_id' => $goods_id,
        ], $page_index, $page_size);

        return $this->outMessage($title, $res);
    }

    /**
     * 获取推广员等级，或红旗手等级
     */
    public function getPromoterLevel()
    {
        $title = '获取推广员等级，或红旗手等级';

        $nfx_goods_service = new NfxGoods();
        $res = $nfx_goods_service->getPromoterLevel();

        return $this->outMessage($title, $res);
    }

    /**
     * 获取商品分类
     */
    public function getGoodsCategory()
    {
        $title = '获取商品分类';

        $nfx_goods_service = new NfxGoods();
        $res = $nfx_goods_service->getPromoterGoodsCategory($this->uid);

        return $this->outMessage($title, $res);
    }

    /**
     * 处理商品分享
     */
    public function dealWithGoodsShare()
    {
        $title = '处理商品分享';

        $share_uid = $this->params['share_uid'];
        $buyer_uid = $this->uid;
        $goods_id = $this->params['goods_id'];
        if(empty($share_uid) || empty($buyer_uid) || empty($goods_id)){
            return $this->outMessage($title, '参数有误', ERROR);
        }

        $nfx_goods_service = new NfxGoods();
        $res = $nfx_goods_service->dealWithGoodsShare($share_uid, $buyer_uid, $goods_id);

        return $this->outMessage($title, $res);
    }


}